<script>
  layui.config({
    base: '/static/customAdmin/'
  }).extend({
    index: 'lib/index'
  }).use(['index'], async () => {
    const {$, form, layer, admin} = layui;

    //基础参数版本
    await admin.getClearanceVersionData()

    let edit_password_index;
    $("body").on("click", ".edit_password", function () {
      edit_password_index = layer.open({
        type: 1,
        title: '修改密码',
        shadeClose: true,
        area: admin.screen() < 2 ? ['80%', '300px'] : ['550px', '280px'],
        content: $('#edit_password_template').html()
      });
    });

    await form.verify({
      password_confirmation: function (value, item) {
        if (!(/^[\S]{6,16}$/.test(value))) {
          return '密码必须6到16位，且不能出现空格';
        } else if ($("input[name='password']").val() !== value) {
          return '密码不一致';
        }
      }
      , password: [
        /^[\S]{8,16}$/
        , '密码必须6到16位，且不能出现空格'
      ]
    });

    form.on('submit(edit_password_save)', async (data) => {
      layer.load(2);
      try {
        const item = await admin.post(`/user/change_pwd`, data.field);
        if (item.status) {
          layer.close(edit_password_index)
        }
      } catch (e) {
        console.log(e)
      }
      layer.closeAll('loading');
    });
  });
</script>